Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding agent for caching recipient ids and extra tests for these addi… #35

Merged
merged 12 commits into from
Aug 8, 2024

Conversation

MatthewWeppenaar
Copy link
Contributor

…tional implementations

@@ -0,0 +1,36 @@
defmodule TurnJunebugExpressway.TurnAgent do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could use a better name. MessageRecipientIdCache, perhaps?

@@ -11,6 +11,8 @@ defmodule TurnJunebugExpressway.Application do

# Define workers and child supervisors to be supervised
children = [
# Start Agent
{TurnJunebugExpressway.TurnAgent, name: :my_cache},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could name this better here as well.

value = Map.get(message, "recipient_id")
# IO.puts("#{message}")
# IO.puts("#{inspect(key)}, #{inspect(value)}")
TurnJunebugExpressway.TurnAgent.put(:my_cache, key, value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TTL needs to be configurable, so we should probably look it up from the application environment and pass it in here.

@@ -5,6 +5,8 @@
# is restricted to this project.
import Config

config :turn_junebug_expressway, :agent, ttl: System.get_env("MESSAGE_TTL", "10000")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure MESSAGE_TTL really describes what this value is used for.

@@ -0,0 +1,45 @@
defmodule TurnJunebugExpressway.MessageRecipientIdCache do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename the file to match the new module name?

end

def handle_call({:put, key, value, ttl}, _from, state) do
Process.send_after(self(), {:expire, key}, ttl)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing it this way means that if we set the same key multiple times we're not extending the lifetime -- each call will schedule a new expiry. I don't think that's a problem for message ids, but we may want to add a comment noting that behaviour.

@MatthewWeppenaar MatthewWeppenaar merged commit e8d734d into develop Aug 8, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants